home *** CD-ROM | disk | FTP | other *** search
/ AOL File Library: 2,801 to 2,900 / aol-file-protocol-4400-2801-to-2900.zip / AOLDLs / C++ Files Library / Acere (PowerPlant, Game) 1.2 / AcereÄ.sit / Acereƒ / Code / CardDeck.cp < prev    next >
Text File  |  1995-03-05  |  24KB  |  843 lines

  1. #include "CardDeck.h"
  2. #include "CTextDoc.h"
  3. #include "AcereApp.h"
  4. #include "CardWindow.h"
  5.  
  6. #define kNoCard -1
  7.  
  8. static    RGBColor    RGBwhite;
  9. static    RGBColor    RGBdkGrey;
  10.  
  11. extern    unsigned long     ourAvailRam;
  12. extern    Boolean        hasSmallScreen;
  13.  
  14.  
  15. extern    CTextDoc        *theDoc;
  16. extern    CardWindow    *gMainWindow;
  17. CardDeck    *theDeck;
  18. RGBColor    myBlack, myWhite;
  19.  
  20.  
  21. CardDeck::CardDeck()
  22. {
  23.     short    i;
  24.     
  25.     theDeck = this;
  26.     
  27.     GetDateTime((unsigned long *)&qd.randSeed);        //    initialize randomizer when we create a new deck object
  28.                                             //    since Generate doesn't do this, we only do it once per session
  29.     
  30.     RGBwhite.red = RGBwhite.blue = RGBwhite.green = 0xffff;
  31.     RGBdkGrey.red = RGBdkGrey.blue = RGBdkGrey.green = 0x3fff;
  32.     myBlack.red = myBlack.green = myBlack.blue = 0;
  33.     myWhite.red = myWhite.green = myWhite.blue = 0xFFFF;
  34.     
  35.     for (i=0; i< 4; i++)
  36.     {
  37.         suitCIcons[i] = GetCIcon(2000+i);
  38.     }
  39.         
  40.     columnOffsets[0] = 6;
  41.     columnOffsets[1] = 24;
  42.     columnOffsets[2] = 42;
  43.     
  44.     GetGWorld(&mSavePort, &mSaveDevice);
  45.     
  46.     gwRect.top = gwRect.left = 0;
  47.     gwRect.right = GetCardWidth() * (NumCardsPerSuit + 1);
  48.     gwRect.bottom = GetCardHeight() * NumSuits;
  49.     
  50.     QDErr    err = ::NewGWorld(&cardGWorld, 4, &gwRect, 0L, nil, 0L);
  51.         
  52.     ThrowIfOSErr_(err);
  53.     ThrowIfNil_(cardGWorld);
  54.     
  55.         // Make offscreen GWorld the current one and prepare it
  56.         // for drawing by setting the coordinate system, and locking
  57.         // and erasing the pixels.
  58.     
  59.     ::SetGWorld(cardGWorld, nil);
  60. //    ::SetOrigin(gwRect.left, gwRect.top);
  61.     ::LockPixels(::GetGWorldPixMap(cardGWorld));
  62.             /* set the foreground color to black */
  63.             
  64.     RGBForeColor( &myBlack );
  65.     RGBBackColor( &myWhite );
  66.     
  67.     ::EraseRect(&gwRect);
  68.  
  69.     GetShortCardMask();
  70.  
  71.     offScreen = ::GetGWorldPixMap( cardGWorld );
  72.     
  73.     ::SetGWorld(mSavePort, mSaveDevice);
  74.  
  75.     ZapOldDeck();
  76.     GenerateNewDeck(true);
  77.     
  78.     nextCardPosition = 0;
  79. }
  80.  
  81. CardDeck::~CardDeck()
  82. {
  83.     short i;
  84.     for (i=0; i< 4; i++)
  85.     {
  86.         DisposCIcon(suitCIcons[i]);
  87.     }
  88.     
  89.     DisposeGWorld(cardGWorld);
  90. }
  91.  
  92.     
  93. void  CardDeck::GenerateNewDeck(Boolean doOffScreenDraw)
  94. {
  95. #define abs(x) (x) < 0 ? (-x) : (x)
  96.  
  97.     unsigned short    i = 0, tempShort;
  98.     Boolean        happy;
  99.     
  100.     CardStruct    theCardInfo;
  101.     Rect            theRectToDraw;
  102.     
  103.     for (i = 0; i < NumCards; i++)
  104.         theCardPositions[i] = -1;
  105.     
  106.     for (i = 0; i < NumCards; i++)
  107.     {
  108.         happy = false;
  109.         do
  110.         {
  111.             tempShort = abs(Random());
  112.             tempShort =  tempShort% NumCards;
  113.             if ((theCardPositions[tempShort] == -1) && (theCards[i] == -1))    //    card is unassigned & so is position
  114.             {
  115.                 happy = true;
  116.                 theCardPositions[tempShort] = i;
  117.                 theCards[i] = tempShort;
  118.             }
  119.         } while (!happy);
  120.         
  121.         if (doOffScreenDraw)
  122.         {
  123.             GetCardInfo(theCards[i], &theCardInfo);
  124.             CalcOffScreenRect(&theCardInfo, &theRectToDraw);
  125.             DrawCardOffScreen(&theCardInfo, theRectToDraw, false);
  126.         }
  127.     }    
  128. }
  129.  
  130. void  CardDeck::ZapOldDeck()        //    after we finish a game to cleanup before generating a new one
  131. {
  132.     short    i;
  133.     
  134.     for (i=0; i < NumCards; i++)
  135.     {
  136.         theCards[i] = -1;
  137.     }
  138. }
  139.  
  140.  
  141. void    CardDeck::DrawCardOffScreen(CardStruct *whichCard, Rect theRect, Boolean highlight)
  142. {
  143.     Rect            tempRect, theDrawRect = theRect;
  144.     RGBColor        theBackColor;
  145. //    CIconHandle    theIcon;
  146.     short        saveFont, saveSize;
  147.     Str15        cardString;
  148.     
  149.     ::SetGWorld(cardGWorld, nil);
  150. //    ::SetOrigin(gwRect.left, gwRect.top);
  151.     ::LockPixels(::GetGWorldPixMap(cardGWorld));
  152.     ::EraseRect(&theRect);
  153.  
  154.     Boolean        fullCard = (theRect.bottom - theRect.top > 30);
  155.     
  156.     if (whichCard == nil)
  157.         return;
  158.     
  159.     if (whichCard->card == kNoCard)
  160.         return;
  161.     
  162. //    GetCardInfo(whichCard, theCard);
  163.         
  164.      GetBackColor(&theBackColor);
  165.      
  166.      if ((highlight) && fullCard)
  167.          RGBBackColor(&RGBdkGrey);
  168.      else
  169.          RGBBackColor(&RGBwhite);
  170.      
  171.      if (fullCard)
  172.      {
  173.          FillRoundRect(&theRect, 20, 20, &qd.white);
  174. //         EraseRoundRect(&theRect, 20, 20);            //    otherwise puts the pattern in.
  175.          FrameRoundRect(&theRect, 20, 20);
  176.      }
  177.      else                                    //    we need to do PART of a rounded rectangle
  178.      {
  179. //        DrawShortCardBoundary(theRect);
  180.      }
  181.  
  182.      tempRect.top = theRect.top + 2;
  183.      tempRect.left = theRect.left + 4;
  184.      SizeRect(&tempRect, 12, 16);
  185.      
  186. //     theIcon = theApp->suitPats[whichCard->suit][0];
  187.      
  188.      PlotCIcon(&tempRect,theApp->suitPats[whichCard->suit][0]);
  189.  
  190.      saveFont = qd.thePort->txFont;
  191.      saveSize = qd.thePort->txSize;
  192.      
  193.      cardString[0] = 1;
  194.      
  195.      switch(whichCard->card)
  196.      {
  197.          case 1:
  198.              cardString[1] = 'A';
  199.              break;
  200.          case 11:
  201.              cardString[1] = 'J';
  202.              break;
  203.          case 12:
  204.              cardString[1] = 'Q';
  205.              break;
  206.          case 13:
  207.              cardString[1] = 'K';
  208.              break;
  209.          default:
  210.              NumToString((long)whichCard->card, cardString);
  211.              
  212.      }
  213.      
  214.      TextSize(12);
  215.      TextFont(systemFont);
  216.      
  217.      tempRect.left += 14;
  218.      MoveTo(tempRect.left, tempRect.bottom -4);
  219.      DrawString(cardString);
  220.      
  221. //     theDrawRect.top += 20;
  222.      
  223.      if (fullCard)
  224.      {
  225.          if (cardString[1] == 'A')
  226.          {
  227.             tempRect.left = theDrawRect.left + ((theDrawRect.right - theDrawRect.left)/2) - 12;
  228.             tempRect.top = theDrawRect.top +  ((theDrawRect.bottom - theDrawRect.top)/2) - 16;
  229.             SizeRect(&tempRect, 24, 32);
  230.             PlotCIcon(&tempRect, suitCIcons[whichCard->suit]);
  231.  
  232.             tempRect.top = theRect.bottom - 19;
  233.             tempRect.left = theRect.right - 15;
  234.             SizeRect(&tempRect, 12, 16);
  235.             PlotCIcon(&tempRect,theApp->suitPats[whichCard->suit][1]);
  236.          }
  237.          else if (cardString[1] == '2')
  238.          {
  239.             tempRect.left = theDrawRect.left + columnOffsets[2];
  240.             tempRect.top = theDrawRect.top +  GetRowOffset(1, 3);
  241.             SizeRect(&tempRect, 12, 16);
  242.             
  243.             PlotCIcon(&tempRect, theApp->suitPats[whichCard->suit][0]);
  244.             
  245.             tempRect.left = theDrawRect.left + columnOffsets[0];
  246.             tempRect.top = theDrawRect.top +  GetRowOffset(3, 3);
  247.             SizeRect(&tempRect, 12, 16);
  248.             
  249.             PlotCIcon(&tempRect, theApp->suitPats[whichCard->suit][1]);
  250.          }
  251.          else if (cardString[1] == '3')
  252.          {
  253.             tempRect.left = theDrawRect.left + columnOffsets[2];
  254.             tempRect.top = theDrawRect.top +  GetRowOffset(1, 3);
  255.             SizeRect(&tempRect, 12, 16);
  256.             
  257.             PlotCIcon(&tempRect, theApp->suitPats[whichCard->suit][0]);
  258.             
  259.             tempRect.left = theDrawRect.left + columnOffsets[1];
  260.             tempRect.top = theDrawRect.top + GetRowOffset(2, 3);
  261.             SizeRect(&tempRect, 12, 16);
  262.             
  263.             PlotCIcon(&tempRect, theApp->suitPats[whichCard->suit][0]);
  264.             
  265.             tempRect.left = theDrawRect.left + columnOffsets[0];
  266.             tempRect.top = theDrawRect.top +  GetRowOffset(3, 3);
  267.             SizeRect(&tempRect, 12, 16);
  268.             
  269.             PlotCIcon(&tempRect, theApp->suitPats[whichCard->suit][1]);
  270.          }
  271.          else if (cardString[1] == '4')
  272.          {
  273.             tempRect.left = theDrawRect.left + columnOffsets[2];
  274.             tempRect.top = theDrawRect.top +  GetRowOffset(1, 3);
  275.             SizeRect(&tempRect, 12, 16);
  276.             
  277.             PlotCIcon(&tempRect, theApp->suitPats[whichCard->suit][0]);
  278.             
  279.             tempRect.left = theDrawRect.left + columnOffsets[0];
  280.             tempRect.top = theDrawRect.top +  GetRowOffset(1, 3);
  281.             SizeRect(&tempRect, 12, 16);
  282.             
  283.             PlotCIcon(&tempRect, theApp->suitPats[whichCard->suit][0]);
  284.             
  285.             tempRect.left = theDrawRect.left + columnOffsets[0];
  286.             tempRect.top = theDrawRect.top +  GetRowOffset(3, 3);
  287.             SizeRect(&tempRect, 12, 16);
  288.             
  289.             PlotCIcon(&tempRect, theApp->suitPats[whichCard->suit][1]);
  290.             
  291.             tempRect.left = theDrawRect.left + columnOffsets[2];
  292.             tempRect.top = theDrawRect.top +  GetRowOffset(3, 3);
  293.             SizeRect(&tempRect, 12, 16);
  294.             
  295.             PlotCIcon(&tempRect, theApp->suitPats[whichCard->suit][1]);
  296.          }
  297.          else if (cardString[1] == '5')
  298.          {
  299.             tempRect.left = theDrawRect.left + columnOffsets[2];
  300.             tempRect.top = theDrawRect.top +  GetRowOffset(1, 3);
  301.             SizeRect(&tempRect, 12, 16);
  302.             
  303.             PlotCIcon(&tempRect, theApp->suitPats[whichCard->suit][0]);
  304.             
  305.             tempRect.left = theDrawRect.left + columnOffsets[0];
  306.             tempRect.top = theDrawRect.top +  GetRowOffset(1, 3);
  307.             SizeRect(&tempRect, 12, 16);
  308.             
  309.             PlotCIcon(&tempRect, theApp->suitPats[whichCard->suit][0]);
  310.             
  311.             tempRect.left = theDrawRect.left + columnOffsets[1];
  312.             tempRect.top = theDrawRect.top + GetRowOffset(2, 3);
  313.             SizeRect(&tempRect, 12, 16);
  314.             
  315.             PlotCIcon(&tempRect, theApp->suitPats[whichCard->suit][0]);
  316.             
  317.             tempRect.left = theDrawRect.left + columnOffsets[0];
  318.             tempRect.top = theDrawRect.top +  GetRowOffset(3, 3);
  319.             SizeRect(&tempRect, 12, 16);
  320.             
  321.             PlotCIcon(&tempRect, theApp->suitPats[whichCard->suit][1]);
  322.             
  323.             tempRect.left = theDrawRect.left + columnOffsets[2];
  324.             tempRect.top = theDrawRect.top +  GetRowOffset(3, 3);
  325.             SizeRect(&tempRect, 12, 16);
  326.             
  327.             PlotCIcon(&tempRect, theApp->suitPats[whichCard->suit][1]);
  328.          }
  329.          else if (cardString[1] == '6')
  330.          {
  331.             tempRect.left = theDrawRect.left + columnOffsets[0];
  332.             tempRect.top = theDrawRect.top +  GetRowOffset(1, 3);
  333.             SizeRect(&tempRect, 12, 16);
  334.             
  335.             PlotCIcon(&tempRect, theApp->suitPats[whichCard->suit][0]);
  336.             
  337.             tempRect.left = theDrawRect.left + columnOffsets[2];
  338.             tempRect.top = theDrawRect.top +  GetRowOffset(1, 3);
  339.             SizeRect(&tempRect, 12, 16);
  340.             
  341.             PlotCIcon(&tempRect, theApp->suitPats[whichCard->suit][0]);
  342.             
  343.             tempRect.left = theDrawRect.left + columnOffsets[0];
  344.             tempRect.top = theDrawRect.top +  GetRowOffset(2, 3);
  345.             SizeRect(&tempRect, 12, 16);
  346.             
  347.             PlotCIcon(&tempRect, theApp->suitPats[whichCard->suit][0]);
  348.             
  349.             tempRect.left = theDrawRect.left + columnOffsets[2];
  350.             tempRect.top = theDrawRect.top +  GetRowOffset(2, 3);
  351.             SizeRect(&tempRect, 12, 16);
  352.             
  353.             PlotCIcon(&tempRect, theApp->suitPats[whichCard->suit][0]);
  354.             
  355.             tempRect.left = theDrawRect.left + columnOffsets[0];
  356.             tempRect.top = theDrawRect.top +  GetRowOffset(3, 3);
  357.             SizeRect(&tempRect, 12, 16);
  358.             PlotCIcon(&tempRect, theApp->suitPats[whichCard->suit][1]);
  359.             
  360.             tempRect.left = theDrawRect.left + columnOffsets[2];
  361.             tempRect.top = theDrawRect.top +  GetRowOffset(3, 3);
  362.             SizeRect(&tempRect, 12, 16);
  363.             PlotCIcon(&tempRect, theApp->suitPats[whichCard->suit][1]);
  364.             
  365.          }
  366.          else if (cardString[1] == '7')
  367.          {
  368.             tempRect.left = theDrawRect.left + columnOffsets[0];
  369.             tempRect.top = theDrawRect.top +  GetRowOffset(1, 3);
  370.             SizeRect(&tempRect, 12, 16);
  371.             PlotCIcon(&tempRect, theApp->suitPats[whichCard->suit][0]);
  372.             
  373.             tempRect.left = theDrawRect.left + columnOffsets[2];
  374.             tempRect.top = theDrawRect.top +  GetRowOffset(1, 3);
  375.             SizeRect(&tempRect, 12, 16);
  376.             PlotCIcon(&tempRect, theApp->suitPats[whichCard->suit][0]);
  377.             
  378.             tempRect.left = theDrawRect.left + columnOffsets[0];
  379.             tempRect.top = theDrawRect.top +  GetRowOffset(2, 3);
  380.             SizeRect(&tempRect, 12, 16);
  381.             PlotCIcon(&tempRect, theApp->suitPats[whichCard->suit][0]);
  382.             
  383.             tempRect.left = theDrawRect.left + columnOffsets[2];
  384.             tempRect.top = theDrawRect.top +  GetRowOffset(2, 3);
  385.             SizeRect(&tempRect, 12, 16);
  386.             PlotCIcon(&tempRect, theApp->suitPats[whichCard->suit][0]);
  387.             
  388.             tempRect.left = theDrawRect.left + columnOffsets[1];
  389.             tempRect.top = theDrawRect.top + GetRowOffset(2, 3);
  390.             SizeRect(&tempRect, 12, 16);
  391.             PlotCIcon(&tempRect, theApp->suitPats[whichCard->suit][0]);
  392.             
  393.             tempRect.left = theDrawRect.left + columnOffsets[0];
  394.             tempRect.top = theDrawRect.top +  GetRowOffset(3, 3);
  395.             SizeRect(&tempRect, 12, 16);
  396.             PlotCIcon(&tempRect, theApp->suitPats[whichCard->suit][1]);
  397.             
  398.             tempRect.left = theDrawRect.left + columnOffsets[2];
  399.             tempRect.top = theDrawRect.top +  GetRowOffset(3, 3);
  400.             SizeRect(&tempRect, 12, 16);
  401.             PlotCIcon(&tempRect, theApp->suitPats[whichCard->suit][1]);
  402.             
  403.          }
  404.          else if (cardString[1] == '8')
  405.          {
  406.             tempRect.left = theDrawRect.left + columnOffsets[0];
  407.             tempRect.top = theDrawRect.top +  GetRowOffset(1, 4);
  408.             SizeRect(&tempRect, 12, 16);
  409.             PlotCIcon(&tempRect, theApp->suitPats[whichCard->suit][0]);
  410.             
  411.             tempRect.left = theDrawRect.left + columnOffsets[2];
  412.             tempRect.top = theDrawRect.top +  GetRowOffset(1, 4);
  413.             SizeRect(&tempRect, 12, 16);
  414.             PlotCIcon(&tempRect, theApp->suitPats[whichCard->suit][0]);
  415.             
  416.             tempRect.left = theDrawRect.left + columnOffsets[0];
  417.             tempRect.top = theDrawRect.top +  GetRowOffset(2, 4);
  418.             SizeRect(&tempRect, 12, 16);
  419.             PlotCIcon(&tempRect, theApp->suitPats[whichCard->suit][0]);
  420.             
  421.             tempRect.left = theDrawRect.left + columnOffsets[2];
  422.             tempRect.top = theDrawRect.top +  GetRowOffset(2, 4);
  423.             SizeRect(&tempRect, 12, 16);
  424.             PlotCIcon(&tempRect, theApp->suitPats[whichCard->suit][0]);
  425.             
  426.             tempRect.left = theDrawRect.left + columnOffsets[0];
  427.             tempRect.top = theDrawRect.top +  GetRowOffset(3, 4);
  428.             SizeRect(&tempRect, 12, 16);
  429.             PlotCIcon(&tempRect, theApp->suitPats[whichCard->suit][1]);
  430.             
  431.             tempRect.left = theDrawRect.left + columnOffsets[2];
  432.             tempRect.top = theDrawRect.top +  GetRowOffset(3, 4);
  433.             SizeRect(&tempRect, 12, 16);
  434.             PlotCIcon(&tempRect, theApp->suitPats[whichCard->suit][1]);
  435.             
  436.             tempRect.left = theDrawRect.left + columnOffsets[0];
  437.             tempRect.top = theDrawRect.top +  GetRowOffset(4, 4);
  438.             SizeRect(&tempRect, 12, 16);
  439.             PlotCIcon(&tempRect, theApp->suitPats[whichCard->suit][1]);
  440.             
  441.             tempRect.left = theDrawRect.left + columnOffsets[2];
  442.             tempRect.top = theDrawRect.top +  GetRowOffset(4, 4);
  443.             SizeRect(&tempRect, 12, 16);
  444.             PlotCIcon(&tempRect, theApp->suitPats[whichCard->suit][1]);        
  445.             
  446.          }
  447.          else if (cardString[1] == '9')
  448.          {
  449.             tempRect.left = theDrawRect.left + columnOffsets[0];
  450.             tempRect.top = theDrawRect.top +  GetRowOffset(1, 4);
  451.             SizeRect(&tempRect, 12, 16);
  452.             PlotCIcon(&tempRect, theApp->suitPats[whichCard->suit][0]);
  453.             
  454.             tempRect.left = theDrawRect.left + columnOffsets[2];
  455.             tempRect.top = theDrawRect.top +  GetRowOffset(1, 4);
  456.             SizeRect(&tempRect, 12, 16);
  457.             PlotCIcon(&tempRect, theApp->suitPats[whichCard->suit][0]);
  458.             
  459.             tempRect.left = theDrawRect.left + columnOffsets[0];
  460.             tempRect.top = theDrawRect.top +  GetRowOffset(2, 4);
  461.             SizeRect(&tempRect, 12, 16);
  462.             PlotCIcon(&tempRect, theApp->suitPats[whichCard->suit][0]);
  463.             
  464.             tempRect.left = theDrawRect.left + columnOffsets[2];
  465.             tempRect.top = theDrawRect.top +  GetRowOffset(2, 4);
  466.             SizeRect(&tempRect, 12, 16);
  467.             PlotCIcon(&tempRect, theApp->suitPats[whichCard->suit][0]);
  468.             
  469.             tempRect.left = theDrawRect.left + columnOffsets[0];
  470.             tempRect.top = theDrawRect.top +  GetRowOffset(3, 4);
  471.             SizeRect(&tempRect, 12, 16);
  472.             PlotCIcon(&tempRect, theApp->suitPats[whichCard->suit][1]);
  473.             
  474.             tempRect.left = theDrawRect.left + columnOffsets[2];
  475.             tempRect.top = theDrawRect.top +  GetRowOffset(3, 4);
  476.             SizeRect(&tempRect, 12, 16);
  477.             PlotCIcon(&tempRect, theApp->suitPats[whichCard->suit][1]);
  478.             
  479.             tempRect.left = theDrawRect.left + columnOffsets[0];
  480.             tempRect.top = theDrawRect.top +  GetRowOffset(4, 4);
  481.             SizeRect(&tempRect, 12, 16);
  482.             PlotCIcon(&tempRect, theApp->suitPats[whichCard->suit][1]);
  483.             
  484.             tempRect.left = theDrawRect.left + columnOffsets[2];
  485.             tempRect.top = theDrawRect.top +  GetRowOffset(4, 4);
  486.             SizeRect(&tempRect, 12, 16);
  487.             PlotCIcon(&tempRect, theApp->suitPats[whichCard->suit][1]);        
  488.             
  489.             tempRect.left = theDrawRect.left + columnOffsets[1];
  490.             tempRect.top = theDrawRect.top +  GetRowOffset(2, 4) + (GetRowOffset(3, 4) - GetRowOffset(2, 4))/2;
  491.             SizeRect(&tempRect, 12, 16);
  492.             PlotCIcon(&tempRect, theApp->suitPats[whichCard->suit][0]);
  493.             
  494.          }
  495.          else if (cardString[1] == '1')
  496.          {
  497.             tempRect.left = theDrawRect.left + columnOffsets[0];
  498.             tempRect.top = theDrawRect.top +  GetRowOffset(1, 4);
  499.             SizeRect(&tempRect, 12, 16);
  500.             PlotCIcon(&tempRect, theApp->suitPats[whichCard->suit][0]);
  501.             
  502.             tempRect.left = theDrawRect.left + columnOffsets[2];
  503.             tempRect.top = theDrawRect.top +  GetRowOffset(1, 4);
  504.             SizeRect(&tempRect, 12, 16);
  505.             PlotCIcon(&tempRect, theApp->suitPats[whichCard->suit][0]);
  506.             
  507.             tempRect.left = theDrawRect.left + columnOffsets[0];
  508.             tempRect.top = theDrawRect.top +  GetRowOffset(2, 4);
  509.             SizeRect(&tempRect, 12, 16);
  510.             PlotCIcon(&tempRect, theApp->suitPats[whichCard->suit][0]);
  511.             
  512.             tempRect.left = theDrawRect.left + columnOffsets[2];
  513.             tempRect.top = theDrawRect.top +  GetRowOffset(2, 4);
  514.             SizeRect(&tempRect, 12, 16);
  515.             PlotCIcon(&tempRect, theApp->suitPats[whichCard->suit][0]);
  516.             
  517.             tempRect.left = theDrawRect.left + columnOffsets[0];
  518.             tempRect.top = theDrawRect.top +  GetRowOffset(3, 4);
  519.             SizeRect(&tempRect, 12, 16);
  520.             PlotCIcon(&tempRect, theApp->suitPats[whichCard->suit][1]);
  521.             
  522.             tempRect.left = theDrawRect.left + columnOffsets[2];
  523.             tempRect.top = theDrawRect.top +  GetRowOffset(3, 4);
  524.             SizeRect(&tempRect, 12, 16);
  525.             PlotCIcon(&tempRect, theApp->suitPats[whichCard->suit][1]);
  526.             
  527.             tempRect.left = theDrawRect.left + columnOffsets[0];
  528.             tempRect.top = theDrawRect.top +  GetRowOffset(4, 4);
  529.             SizeRect(&tempRect, 12, 16);
  530.             PlotCIcon(&tempRect, theApp->suitPats[whichCard->suit][1]);
  531.             
  532.             tempRect.left = theDrawRect.left + columnOffsets[2];
  533.             tempRect.top = theDrawRect.top +  GetRowOffset(4, 4);
  534.             SizeRect(&tempRect, 12, 16);
  535.             PlotCIcon(&tempRect, theApp->suitPats[whichCard->suit][1]);        
  536.             
  537.             tempRect.left = theDrawRect.left + columnOffsets[1];
  538.             tempRect.top = theDrawRect.top +  GetRowOffset(1, 4) + (GetRowOffset(2, 4) - GetRowOffset(1, 4))/2;
  539.             SizeRect(&tempRect, 12, 16);
  540.             PlotCIcon(&tempRect, theApp->suitPats[whichCard->suit][0]);
  541.             
  542.             tempRect.left = theDrawRect.left + columnOffsets[1];
  543.             tempRect.top = theDrawRect.top +  GetRowOffset(3, 4) + (GetRowOffset(4, 4) - GetRowOffset(3, 4))/2;
  544.             SizeRect(&tempRect, 12, 16);
  545.             PlotCIcon(&tempRect, theApp->suitPats[whichCard->suit][1]);
  546.          }
  547.          else
  548.          {
  549.              PicHandle        ourPicture;
  550.              
  551.              ourPicture = GetPicture(257+ (3*whichCard->suit) + (whichCard->card - 11));
  552.  
  553.              tempRect.left = theRect.left + ((theRect.right - theRect.left)/2) - 17;
  554.              tempRect.top = theRect.top +  ((theRect.bottom - theRect.top)/2) - 30;
  555.             SizeRect(&tempRect, 34, 69);
  556.              
  557.             DrawPicture(ourPicture, &tempRect);
  558.             ReleaseResource((Handle)ourPicture);
  559.  
  560.             tempRect.top = theRect.bottom - 19;
  561.             tempRect.left = theRect.right - 15;
  562.             SizeRect(&tempRect, 12, 16);
  563.          
  564.             PlotCIcon(&tempRect,theApp->suitPats[whichCard->suit][1]);
  565.          }
  566.          
  567.      }
  568.      
  569.      //    restore everything
  570.      
  571.      TextSize(saveSize);
  572.      TextFont(saveFont);
  573.      
  574. //     RGBBackColor(&theBackColor);
  575.     ::UnlockPixels(::GetGWorldPixMap(cardGWorld));
  576.     ::SetGWorld(mSavePort, mSaveDevice);
  577. }
  578.  
  579. void    CardDeck::DrawCard(PlayingCard *whichCard, Rect theRect, Boolean highlight)
  580. {
  581.     Rect        offscreenRect, adjustedRect = theRect;
  582.     GrafPtr    myPort = gMainWindow->GetMacPort();
  583.     
  584.     CalcOffScreenRect(whichCard, &offscreenRect);
  585.     
  586.     if (theRect.bottom > (theRect.top + 30))    
  587.     {
  588.         OffsetRgn(fullCardMask, theRect.left - (*fullCardMask)->rgnBBox.left, 
  589.                 theRect.top - (*fullCardMask)->rgnBBox.top);
  590.         CopyBits((BitMap *)*offScreen, &myPort->portBits, &offscreenRect, &theRect, srcCopy, fullCardMask);
  591.         FrameRgn(fullCardMask);
  592.     }
  593.     else
  594.     {
  595.         adjustedRect.bottom = adjustedRect.top + GetCardHeight();
  596.         OffsetRgn(shortCardMask, theRect.left - (*shortCardMask)->rgnBBox.left, 
  597.                 theRect.top - (*shortCardMask)->rgnBBox.top);
  598.         CopyBits((BitMap *)*offScreen, &myPort->portBits, &offscreenRect, &adjustedRect, srcCopy, shortCardMask);
  599.         FrameRgn(shortCardMask);
  600.     }
  601. }
  602.  
  603. short    CardDeck::GetNextCardPosition(void)
  604. {
  605.     nextCardPosition++;
  606.     if (nextCardPosition >= NumCards)
  607.         return (kNoCard);
  608.     
  609.     return ((short)nextCardPosition);
  610. }
  611.  
  612. short    CardDeck::GetPositionValue(short whichPosition)
  613. {
  614.     return ((short)theCardPositions[whichPosition]);
  615. }
  616.  
  617. void        CardDeck::GetCardInfo(short whichCard, CardStruct *cardInfo)
  618. {
  619.     if ((whichCard == kNoCard) || (whichCard < 0) || (whichCard > NumCards))
  620.     {
  621.         cardInfo->card = kNoCard;
  622.         return;
  623.     }
  624.     cardInfo->suit = whichCard / 13;
  625.     cardInfo->card = (whichCard % 13) + 1;
  626.     if ((cardInfo->suit == 0) || (cardInfo->suit == 3))
  627.         cardInfo->color = blackCard;
  628.     else
  629.         cardInfo->color = redCard;
  630. }
  631.  
  632. void        CardDeck::GetCardInfo(short whichCard, PlayingCard *cardInfo)
  633. {
  634.     if ((whichCard == kNoCard) || (whichCard < 0) || (whichCard > NumCards))
  635.     {
  636.         cardInfo->card = kNoCard;
  637.         return;
  638.     }
  639.     cardInfo->suit = whichCard / 13;
  640.     cardInfo->card = (whichCard % 13) + 1;
  641.     if ((cardInfo->suit == 0) || (cardInfo->suit == 3))
  642.         cardInfo->color = blackCard;
  643.     else
  644.         cardInfo->color = redCard;
  645. }
  646.  
  647. //void    CardDeck::DrawShortCardBoundary(Rect theRect)
  648. void    CardDeck::GetShortCardMask(void)
  649. {
  650.          Rect            tempRect /* = theRect */;
  651.         RgnHandle        /*newRgn, */oldRgn;
  652.          
  653.          tempRect.left = tempRect.top = 0;
  654.          tempRect.right = tempRect.left + GetCardWidth();
  655.          tempRect.bottom = tempRect.top + GetCardHeight();
  656.          
  657.          fullCardMask = NewRgn();
  658.         OpenRgn();
  659.         FrameRoundRect(&tempRect, 20, 20);
  660.         FillRgn(fullCardMask, &qd.black);
  661.         CloseRgn(fullCardMask);
  662.          
  663.          oldRgn = NewRgn();
  664.         OpenRgn();
  665.         tempRect.bottom +=20;
  666.         FrameRoundRect(&tempRect, 20, 20);
  667.         CloseRgn(oldRgn);
  668.         
  669.         shortCardMask = NewRgn();
  670.         OpenRgn();
  671.         tempRect.bottom += 22;
  672.         tempRect.top += 22;
  673.         FrameRoundRect(&tempRect, 20, 20);
  674.         CloseRgn(shortCardMask);
  675.         
  676.         DiffRgn(oldRgn, shortCardMask, shortCardMask);
  677.         
  678.         FillRgn(shortCardMask, &qd.black);
  679.         FrameRgn(shortCardMask);
  680.         
  681. //        DisposeRgn(newRgn);
  682.         DisposeRgn(oldRgn);
  683. }
  684.  
  685. void        CardDeck::CalcOffScreenRect(PlayingCard *whichCard, Rect *theRect)
  686. {
  687.     //    note that the suit is the row and the card is the column. Clever, huh?
  688.     
  689.     theRect->top = GetCardHeight() * whichCard->suit;
  690.     theRect->bottom = theRect->top + GetCardHeight();
  691.     
  692.     theRect->left = GetCardWidth() * whichCard->card;
  693.     theRect->right = theRect->left + GetCardWidth();
  694. }
  695.  
  696. void        CardDeck::CalcOffScreenRect(CardStruct *whichCard, Rect *theRect)
  697. {
  698.     //    note that the suit is the row and the card is the column. Clever, huh?
  699.     
  700.     theRect->top = GetCardHeight() * whichCard->suit;
  701.     theRect->bottom = theRect->top + GetCardHeight();
  702.     
  703.     theRect->left = GetCardWidth() * whichCard->card;
  704.     theRect->right = theRect->left + GetCardWidth();
  705. }
  706.  
  707.  
  708. short    CardDeck::GetCardWidth(void)
  709. {
  710.     if (hasSmallScreen)
  711.         return (50);
  712.     else
  713.         return (60);
  714.  
  715. }
  716. short    CardDeck::GetCardHeight(void)
  717. {
  718.     if (hasSmallScreen)
  719.         return (75);
  720.     else
  721.         return (90);
  722.  
  723. }
  724. PlayingCard::PlayingCard(CardStruct *theStruct) : LPane()
  725. {
  726.         suit = theStruct->suit;
  727.         card = theStruct->card;
  728.         color = theStruct->color;
  729.         itsOwner = theStruct->itsOwner;
  730.         
  731. //        LPane::LPane();
  732.         
  733.         mFrameSize.width = theDeck->GetCardWidth();
  734.         mFrameSize.height = theDeck->GetCardHeight();
  735.         
  736. //        mSuperView = itsSuperView;
  737. //    itsCardInfo = *theStruct;
  738. }
  739.  
  740.  
  741. PlayingCard::~PlayingCard()
  742. {
  743.     
  744. }
  745.  
  746.  
  747. void        PlayingCard::FillDataStruct(CardStruct *theStruct)
  748. {
  749.         suit = theStruct->suit;
  750.         card = theStruct->card;
  751.         color = theStruct->color;
  752.         itsOwner = theStruct->itsOwner;
  753. //    itsCardInfo = *theStruct;
  754. }
  755.  
  756.  
  757. void        SizeRect(Rect *theRect, short width, short height)
  758. {
  759.         theRect->right = theRect->left + width;
  760.         theRect->bottom = theRect->top + height;
  761. }
  762.  
  763. short    GetRowOffset(short whichRow, short numRows)
  764. {
  765.     short    returnVal = 0;
  766.     if (hasSmallScreen)
  767.     {
  768.         switch (numRows)
  769.         {
  770.             case 3:
  771.                 switch(whichRow)
  772.                 {
  773.                     case 1:
  774.                         returnVal = 21;
  775.                         break;
  776.                     case 2:
  777.                         returnVal = 36;
  778.                         break;
  779.                     case 3:
  780.                         returnVal = 51;
  781.                         break;
  782.                 }
  783.                 break;
  784.             case 4:
  785.                 switch(whichRow)
  786.                 {
  787.                     case 1:
  788.                         returnVal = 10;
  789.                         break;
  790.                     case 2:
  791.                         returnVal = 26;
  792.                         break;
  793.                     case 3:
  794.                         returnVal = 42;
  795.                         break;
  796.                     case 4:
  797.                         returnVal = 58;
  798.                         break;
  799.                 }
  800.                 break;
  801.         }
  802.     }
  803.     else
  804.     {
  805.         switch (numRows)
  806.         {
  807.             case 3:
  808.                 switch(whichRow)
  809.                 {
  810.                     case 1:
  811.                         returnVal = 21;
  812.                         break;
  813.                     case 2:
  814.                         returnVal = 42;
  815.                         break;
  816.                     case 3:
  817.                         returnVal = 63;
  818.                         break;
  819.                 }
  820.                 break;
  821.             case 4:
  822.                 switch(whichRow)
  823.                 {
  824.                     case 1:
  825.                         returnVal = 17;
  826.                         break;
  827.                     case 2:
  828.                         returnVal = 35;
  829.                         break;
  830.                     case 3:
  831.                         returnVal = 53;
  832.                         break;
  833.                     case 4:
  834.                         returnVal = 74;
  835.                         break;
  836.                 }
  837.                 break;
  838.         }
  839.  
  840.     }
  841.     return (returnVal);
  842. }
  843.